// "Copyright [2021] <Copyright Shengkai Lin>"

#ifndef OPTICAL_DEVICE_OPTICAL_TRANSCEIVER_H_
#define OPTICAL_DEVICE_OPTICAL_TRANSCEIVER_H_

#include <vector>
#include <queue>
#include "ai_sim.h"


namespace ai_sim {
class OpticalTransceiver : public omnetpp::cSimpleModule {
 private:
     bool detectMode;
    //  double detectPeriod;
     int msgSize;
     int my_index;
     int my_global_index;
     // The last sim_time that have been tested
     omnetpp::simtime_t last_ack_time;
     double safety_interval;
     double detect_period;
     SimpleMsg* selfMsg_detect; // Used to record when to detect
     SimpleMsg* selfMsg_send; // Used to record when the channel is idle
     queue<omnetpp::cMessage*> msg_queue;
     omnetpp::cChannel *out_channel;

 protected:
     void initialize() override;
     void finish() override;
     void sendDetectMsg();
     void replyAck(omnetpp::cMessage* flowmsg);
     void sendMsginQueue();
     void handleReceivingMsg(omnetpp::cMessage *msg);
     void handleSendingMsg(omnetpp::cMessage *msg);
     void handleMessage(omnetpp::cMessage *msg) override;
};

}  // namespace ai_sim

#endif  // OPTICAL_DEVICE_OPTICAL_TRANSCEIVER_H_
